


# 排序
list1 = [12,34,2,41,25,72]

#reversed()是逆向输出，不进行排序
print(list(reversed(list1)))

#sorted()进行排序，默认的正序输出，, reverse=True反转是否为真时，排序后逆向输出，理解为反向输出并排序
print(sorted(list1, reverse=True))

list2 = ["周抗抗", "曹丽丽", "张章", "薛云非" ,"刘洋" ,"黄婷" ,"张晓雪", ]

"""
print(sorted(list2, key=""))
1、有key时，key是一个自定义函数，sorted分别把每一项数据传送给key对应的函数


"""
# def funs(ss):
#     return len(ss)

# sorted接收key调用排序函数返回的长度数字
print(sorted(list2, key=lambda x: len(x)))


list3 = [
    {"id":1, "name":"周抗抗", "age":"35", "salsry":332},
    {"id":2, "name":"周星驰", "age":"31", "salsry":323242},
    {"id":3, "name":"周大发", "age":"42", "salsry":525},
    {"id":4, "name":"周星星", "age":"12", "salsry":126},
    {"id":5, "name":"周润发", "age":"42", "salsry":62},
    {"id":6, "name":"周甜", "age":"22", "salsry":52},
]

# 对list3根据年龄大小规则进行排序
print(sorted(list3, key=lambda d:d["age"]))

# 对工资多少进行排序，反向排序reverse=True
cc = sorted(list3, key= lambda d:d["salsry"], reverse=True)
print(cc)